package cn.gdcp.democ;

import android.content.Intent;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;

public class EditScoreActivity extends AppCompatActivity {
               private EditText editstuno;
               private EditText editname;
               private EditText editenglish;
               private EditText editandroid;
               private Button   updateScore;
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_edit_score);

        initBundler();
        Intent intent=getIntent();
        String name=intent.getStringExtra("NAME");
        String stuno=intent.getStringExtra("STUNO");
        int english=intent.getIntExtra("ENGLISH",0);
        int android=intent.getIntExtra("ANDROID",0);
        editstuno.setText(stuno);
        editname.setText(name);
        editandroid.setText(String.valueOf(android));
        editenglish.setText(String.valueOf(english));
        updateScoreEvent();
    }

    private void updateScoreEvent() {
                    updateScore.setOnClickListener(new View.OnClickListener() {
                        @Override
                        public void onClick(View view) {
                            Intent intent=new Intent();
                            String stuno=editstuno.getText().toString();
                            String name=editname.getText().toString();
                            int android=Integer.valueOf(editandroid.getText().toString());
                            int english=Integer.valueOf(editenglish.getText().toString());
                            intent.putExtra("NAME",name);
                            intent.putExtra("STUNO",stuno);
                            intent.putExtra("ANDROID",android);
                            intent.putExtra("ENGLISH",english);
                            setResult(3001,intent);
                            finish();
                        }
                    });
    }

    private void initBundler() {
                    editstuno=findViewById(R.id.edit_stuno1);
                    editname=findViewById(R.id.edit_name1);
                    editandroid=findViewById(R.id.edit_android1);
                    editenglish=findViewById(R.id.edit_english1);
                    updateScore=findViewById(R.id.update_score);
    }
}
